// import dotenv from 'dotenv';
import web3 from './web3.js';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

// dotenv.config({ path: '../.env' });

const contractName = 'RoleManager';

// 修改路径获取方式
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const abiPath = path.join(__dirname, 'abis', `${contractName}.json`);
const abi = JSON.parse(fs.readFileSync(abiPath, 'utf8'));
// const address = process.env.VITE_ROLEMANAGER_ADDRESS;
const addressPath = path.join(__dirname, 'contract-address.json');
const addresses = JSON.parse(fs.readFileSync(addressPath, 'utf8'));
const address = addresses[contractName];
// console.log(abi);

const roleManager = new web3.eth.Contract(abi, address);
export default roleManager;